
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
node-watch
Advanced tools
The node-watch package is a simple and efficient file system watcher for Node.js. It allows you to monitor changes in files and directories, making it useful for tasks such as live-reloading, automated testing, and more.
Watch a single file
This feature allows you to watch a single file for changes. The callback function is triggered whenever the file is modified.
const watch = require('node-watch');
watch('file.txt', { recursive: false }, function(evt, name) {
console.log('%s changed.', name);
});
Watch a directory recursively
This feature allows you to watch a directory and all its subdirectories for changes. The callback function is triggered whenever any file within the directory or its subdirectories is modified.
const watch = require('node-watch');
watch('directory', { recursive: true }, function(evt, name) {
console.log('%s changed.', name);
});
Filter files to watch
This feature allows you to specify a filter to watch only certain types of files. In this example, only JavaScript files within the directory are monitored for changes.
const watch = require('node-watch');
watch('directory', { filter: /\.js$/ }, function(evt, name) {
console.log('%s changed.', name);
});
Chokidar is a highly efficient and feature-rich file system watcher for Node.js. It supports recursive watching, filtering, and more advanced features like debouncing and throttling. Compared to node-watch, Chokidar offers more configuration options and better performance for large-scale projects.
Gaze is another file watcher for Node.js that supports recursive watching and filtering. It is known for its simplicity and ease of use. While it offers similar functionalities to node-watch, it may not be as performant or feature-rich as Chokidar.
The watch package is a simple file watcher for Node.js. It provides basic functionality for monitoring file changes but lacks some of the advanced features found in Chokidar and node-watch. It is suitable for smaller projects or simpler use cases.
#Node-watch A fs.watch wrapper to watch files or directories(recursively by default).
npm install node-watch
var watch = require('node-watch');
watch('somedir_or_somefile', function(filename) {
console.log(filename, ' changed.');
});
This module currently does not differentiate event like rename
or delete
. Once there is a change, the callback function will be triggered.
recursive
:Watch it recursively or not (defaults to true).
followSymLinks
: Follow symbolic links or not (defaults to false).
maxSymLevel
: The max number of following symbolic links, in order to prevent circular links (defaults to 1).
filter
: node-watch will only watch elements that pass the test implemented by the provided function. The filter function is provided with a full path string argument(defaults to (fullPath) => true
).
watch('somedir', { recursive: false, followSymLinks: true }, function(filename) {
console.log(filename, ' changed.');
});
Since v0.4.0 watch()
will return a fs.FSWatcher like object,
so you can close the watcher or detect change by change
event instead of the old callback function.
var watcher = watch('./');
watcher.on('change', function(file) {
//
});
watcher.on('error', function(err) {
//
});
// close
watcher.close();
###FAQ
watch(['file1', 'file2'], function(file) {
//
});
You can write your own filter function as a higher-order function. For example:
var filter = function(pattern, fn) {
return function(filename) {
if (pattern.test(filename)) {
fn(filename);
}
}
}
// only watch for js files
watch('mydir', filter(/\.js$/, function(filename) {
//
}));
Alternatively, supply a filter function in the options object. For example:
// don't watch node_modules folder
var options = {
filter : function(filename) {
return !/node_modules/.test(filename);
}
};
watch('mydir', options, function(filename) {
//
}));
The second approach helps avoiding the max open files limit
FAQs
A wrapper and enhancements for fs.watch
The npm package node-watch receives a total of 475,034 weekly downloads. As such, node-watch popularity was classified as popular.
We found that node-watch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.